//
//  LSRollingTowView.m
//  LookScore
//
//  Created by wws on 2018/5/4.
//  Copyright © 2018年 ChongQingXunTiCompany. All rights reserved.
//
#define scoreWidth ((LSScreenWidth-80))/3
#import "LSRollingTowView.h"
#import "LSRecommendDetailModel.h"
@interface LSRollingTowView()
@property (nonatomic, strong) NSMutableArray * scoreArray;
@end
@implementation LSRollingTowView{
    
    UILabel * _timeLabel;
    UIImageView * _hostImageView;
    UIImageView * _guestImageView;
    UILabel * _hosetLabel;
    UILabel * _guestLabel;
    
    
}
- (NSMutableArray *)scoreArray{
    if (!_scoreArray) {
        _scoreArray = @[].mutableCopy;
    }
    return _scoreArray;
}


- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        [self addContentView];
    }
    return self;
}

- (void)addContentView{
    
    _timeLabel = [[UILabel alloc] init];
    _timeLabel.text = @"周三017欧冠|05-05 02:45";
    _timeLabel.font = LSFontSize12;
    _timeLabel.numberOfLines = 1;
    _timeLabel.textColor = LSTitleGrayColor2;
    [self addSubview:_timeLabel];
    _timeLabel.sd_layout
    .leftSpaceToView(self, 10)
    .topSpaceToView(self, 10)
    .rightSpaceToView(self, 10)
    .autoHeightRatio(0);
    
    UILabel * vsLabel = [[UILabel alloc] init];
    vsLabel.textColor = LSTitleGrayColor1;
    vsLabel.text = @"VS";
    vsLabel.font = LSFontSize12;
    [self addSubview:vsLabel];
    vsLabel.sd_layout
    .centerXEqualToView(self)
    .topSpaceToView(_timeLabel, 30)
    .autoHeightRatio(0);
    [vsLabel setSingleLineAutoResizeWithMaxWidth:180];
    
    _hostImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"lologo"]];
    [self addSubview:_hostImageView];
    _hostImageView.sd_layout
    .rightSpaceToView(vsLabel, 30)
    .topSpaceToView(_timeLabel, 20)
    .heightIs(27)
    .widthIs(20.5);
    
    _hosetLabel = [[UILabel alloc] init];
    _hosetLabel.text = @"罗马";
    _hosetLabel.font = LSFontSize12;
    _hosetLabel.numberOfLines = 1;
    _hosetLabel.textColor = LSTitleGrayColor1;
    [self addSubview:_hosetLabel];
    _hosetLabel.sd_layout
    .centerXEqualToView(_hostImageView)
    .topSpaceToView(_hostImageView, 10)
    .autoHeightRatio(0);
    [_hosetLabel setSingleLineAutoResizeWithMaxWidth:180];
    
    
    _guestImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"lilogo"]];
    [self addSubview:_guestImageView];
    _guestImageView.sd_layout
    .leftSpaceToView(vsLabel, 30)
    .topSpaceToView(_timeLabel, 20)
    .heightIs(27)
    .widthIs(20.5);
    
    _guestLabel = [[UILabel alloc] init];
    _guestLabel.text = @"利物浦";
    _guestLabel.font = LSFontSize12;
    _guestLabel.numberOfLines = 1;
    _guestLabel.textColor = LSTitleGrayColor1;
    [self addSubview:_guestLabel];
    _guestLabel.sd_layout
    .centerXEqualToView(_guestImageView)
    .topSpaceToView(_guestImageView, 10)
    .autoHeightRatio(0);
    [_guestLabel setSingleLineAutoResizeWithMaxWidth:180];
    
    UIView *backView=[[UIView alloc]init];
    [self addSubview:backView];
    
    backView.sd_layout
    .leftSpaceToView(self, 70)
    .topSpaceToView(_hosetLabel, 15)
    .rightEqualToView(self).offset(-10)
    .heightIs(150);
    
    CGFloat allWidth=0;
    CGFloat allHeight=0;
    NSArray * array = @[@"leftG",@"middleG",@"rigthG",@"leftG",@"middleG",@"rigthG",@"leftG",@"middleG",@"rigthG"];
    NSArray * nameArray = @[@"主胜",@"平局",@"客胜",@"主胜",@"客胜",@"无",@"大球",@"小球",@"无"];
    for (int i=0; i<9; i++) {
        
        UIButton *btn=[[UIButton alloc]init];
        btn.titleLabel.font=LSFontSize9;
        [btn setTitleColor:LSTitleGrayColor1 forState:UIControlStateNormal];
        [btn setTitle:nameArray[i] forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:array[8-i]] forState:UIControlStateNormal];
        [backView addSubview:btn];
        
        btn.sd_layout
        .leftEqualToView(backView).offset(allWidth)
        .topEqualToView(backView).offset(allHeight)
        .widthIs(scoreWidth)
        .heightIs(40);
        
        if((i+1)%3>0){
            allWidth+=scoreWidth+1;
        }else{
            allWidth=0;
        }
        allHeight= 50 * ((i+1)/3);
//        if (i<=2) {
//
//
//        }else if (i<2 && i<=5){
//
//            allHeight= 40 * 1 + 10;
//
//        }else{
//
//            allHeight= 40 * 2 + 20;
//        }
//
        
        [self.scoreArray addObject:btn];
        
    }
    
    UIButton * opBtn = [[UIButton alloc] init];
    [opBtn setImage:[UIImage imageNamed:@"op"] forState:UIControlStateNormal];
    [self addSubview:opBtn];
    opBtn.sd_layout
    .leftSpaceToView(self, 10)
    .topSpaceToView(_hosetLabel, 15)
    .heightIs(40)
    .widthIs(48);
    
    UIButton *ypBtn = [[UIButton alloc] init];
    [ypBtn setImage:[UIImage imageNamed:@"yp"] forState:UIControlStateNormal];
    [self addSubview:ypBtn];
    ypBtn.sd_layout
    .leftEqualToView(opBtn)
    .topSpaceToView(opBtn, 10)
    .heightIs(40)
    .widthIs(48);
    
    UIButton *dxqBtn = [[UIButton alloc] init];
    [dxqBtn setImage:[UIImage imageNamed:@"dxq"] forState:UIControlStateNormal];
    [self addSubview:dxqBtn];
    dxqBtn.sd_layout
    .leftEqualToView(opBtn)
    .topSpaceToView(ypBtn, 10)
    .heightIs(40)
    .widthIs(48);
    
}

- (void)setModel:(LSRecommendDetailModel *)model{
    
    _model = model;
    NSArray * hostArray = [model.HomeTeamInfo componentsSeparatedByString:@"_"];
    NSArray * guestArray = [model.GuestTeamInfo componentsSeparatedByString:@"_"];
    _hosetLabel.text = hostArray.firstObject;
    _guestLabel.text = guestArray.firstObject;
    [_hostImageView sd_setImageWithURL:[NSURL URLWithString:hostArray.lastObject] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        
    }];
    
    [_guestImageView sd_setImageWithURL:[NSURL URLWithString:guestArray.lastObject] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        
    }];
    
    _timeLabel.text = [NSString stringWithFormat:@"%@|%@",model.LeagueName_CN,model.MatchDateTime];
    //欧赔 胜 平 负 无 亚盘 输赢无  大小球 大 小 无
    NSArray * array = [model.Predict_Ou_Ya_Da componentsSeparatedByString:@"_"];
    if ([array.firstObject isEqualToString:@"负"]) {
        UIButton * btn = self.scoreArray[2];
        [btn setTitleColor:LSTitleWhiteColor forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:@"rightO"] forState:UIControlStateNormal];
    }else if ([array.firstObject isEqualToString:@"胜"]){
        UIButton * btn = self.scoreArray[0];
        [btn setTitleColor:LSTitleWhiteColor forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:@"leftO"] forState:UIControlStateNormal];
        
    }else if ([array.firstObject isEqualToString:@"平"]){
        
        UIButton * btn = self.scoreArray[1];
        [btn setTitleColor:LSTitleWhiteColor forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:@"middelO"] forState:UIControlStateNormal];
    }else{
        
    }
    
    if ([array[1] isEqualToString:@"赢"]) {
        UIButton * btn = self.scoreArray[3];
        [btn setTitleColor:LSTitleWhiteColor forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:@"leftO"] forState:UIControlStateNormal];
    }else if ([array[1] isEqualToString:@"输"]){
        UIButton * btn = self.scoreArray[4];
        [btn setTitleColor:LSTitleWhiteColor forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:@"middelO"] forState:UIControlStateNormal];
        
    }else{
        UIButton * btn = self.scoreArray[5];
        [btn setTitleColor:LSTitleWhiteColor forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:@"rightO"] forState:UIControlStateNormal];
        
    }
    
    if ([array.lastObject isEqualToString:@"大"]) {
        UIButton * btn = self.scoreArray[6];
        [btn setTitleColor:LSTitleWhiteColor forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:@"leftO"] forState:UIControlStateNormal];
    }else if([array.lastObject isEqualToString:@"小"]){
        UIButton * btn = self.scoreArray[7];
        [btn setTitleColor:LSTitleWhiteColor forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:@"middelO"] forState:UIControlStateNormal];
    }else{
        
        UIButton * btn = self.scoreArray[8];
        [btn setTitleColor:LSTitleWhiteColor forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:@"rightO"] forState:UIControlStateNormal];
    }
    
    MyLog(@"%ld",array.count);
}
@end
